import java.io.*;
import java.util.Vector;

import weka.classifiers.Classifier;
import weka.core.Instance;
import weka.core.Instances;

class G2P {
	Instance instance;
	Classifier classifier;
	
    G2P(String classifierFile, String dataFile)
    {
    	try{
    		// deserialize model
    		ObjectInputStream ois = 
    			new ObjectInputStream(new FileInputStream(classifierFile));
    		classifier = (Classifier) ois.readObject();
    		ois.close();
	    
    		Instances data = 
    			new Instances(new BufferedReader(new FileReader(dataFile)));
    		// setting class attribute
    		data.setClassIndex(data.numAttributes() - 1);

    		instance = new Instance(20);
    		instance.setDataset(data);
    	}
    	catch (Exception e) {
    		e.printStackTrace();
    	}
    }
    
    public String convert(Vector graphemes)
    {
    	Vector phonemes = new Vector();
    	
    	phonemes.add("-");
    	phonemes.add("-");
    	phonemes.add("-");
    	phonemes.add("-");
    	phonemes.add("-");
    	phonemes.add("-");
    	
    	for ( int g = 6; g < graphemes.size()-6; g++ ) {
    		// graphemes to left, target, to right (=13)
    		for ( int i = 0; i < 13; i++ ){
    			instance.setValue(i+1,graphemes.elementAt(g - 6 + i).toString());
    		}
    		// already processed phonemes
    		for ( int i = 0; i < 6; i++ ){
    			instance.setValue(i+14,phonemes.elementAt(g - i - 1).toString());
    		}
    		try {
    			instance.setValue(0, classifier.classifyInstance(instance));    		
    			phonemes.add(instance.stringValue(0));
    		}
    		catch (Exception e){
    			e.printStackTrace();
    		}
    	}

    	// strip dashes and wrap in '[ ]' // don't wrap in '[ ]' because of interference with silbentrennung, AS
    	String result = "";    	
    	for (int i = 6; i < phonemes.size(); i++){
    		if (!phonemes.elementAt(i).toString().equals("-")){
    			result = result + phonemes.elementAt(i);
    		}
    	}
    	// result = result + "]";
    	return result;
    }

    public void fillVector( String line, Vector graphemes )
    {
    	graphemes.clear();
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	for (int i = 0; i < line.length(); i++){
        	graphemes.add(new Character(line.charAt(i)));
          	graphemes.add(new Character('-'));
       	}
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    	graphemes.add(new Character('-'));
    } 
    
    public static void main(String[] args) 
    {
    	if (args.length != 2)
    	{
    		System.err.println("usage: java -Xmx1024M G2P weka-classifier-file data-format-file.arff");
    		System.err.println("(maximum heap size is depending on classifier)");
    		System.exit(1);
    	}
    	
    	G2P g2p = new G2P(args[0], args[1]);
    	Vector graphemes = new Vector();
	
    	try {
    		java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
    		String line;

    		while (null != (line = stdin.readLine())){
		    //		    System.out.println("Next word:");
		    //		    System.out.println(line);
    			if ( (line.matches("^\\[.*\\] *$")) || (line.matches("^<.*> *$")) ) {
    				System.out.println(line);
    				continue;
    			}
    			g2p.fillVector(line, graphemes);
    			System.out.println(g2p.convert(graphemes));
    		}
    	}
    	catch (java.io.IOException e) { e.printStackTrace(); }
   	  	catch (NumberFormatException e) { e.printStackTrace(); }
    }
}
